// pages/astronomy/astronomy.js
const app = getApp()
var util = require('../../utils/util.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navBarHeight: app.globalData.navBarHeight,
    navTop: app.globalData.navTop,
    noticeText: '',
    imgUrl: 'https://t8.baidu.com/it/u=4193454865,3097077724&fm=3035&app=3035&size=f242,162&n=0&g=0n&f=JPEG?s=D58F0ABE4A6BDEC413019C84030030A9&sec=1683380394&t=ee726089378a3b5af688652849dc21c8',
    tipText: '',
    queryinput: '',
    isMask: false,
    isSet: false,
    isQuery: false,
    hasPwd: true,//是否设置密码
    poster:'',
    password: ''
  },
  //跳转搜索
  goSearch(){
    wx.navigateTo({
      url: '../search/search',
    })
  },

  //监听input
  queryInput: function(e){
    this.setData({
      queryinput: e.detail.value
    })
  },goSet(){
wx.navigateTo({
  url: '/pages/set/set',
})
  },
  //查询
  onQuery(){
    util.check_login()
    app.https_request(util.web_url.checkipwd,{token:wx.getStorageSync('token'),},'POST',false,false,this,getCurrentPages()).then( (res)=>{
      if(res.msg == '您还没有设置密码'){
       this.setData({isMask:true,isSet:true})
       setTimeout(function(){
          this.setData({isMask:true,isSet:true})
       },2000)

      }else{
        var queryinput = this.data.queryinput;
        if(!queryinput){
          util.msg('请输入要查询的代码');return
        }
        this.setData({isQuery:true})
      }
      
      }).catch( (errMsg)=>{});
  },
  //退出查询
  outQuery(){
    this.closeMask()
  },
  //密码输入监听
  pwdInput(e){
    this.setData({
      password: e.detail.value
    })
  },
  //确认查询
  onsearch(){
  

    var password = this.data.password;
    if(!password){
      util.msg('请输入密码');return
    }
  
    app.https_request(util.web_url.checkipwd,{token:wx.getStorageSync('token'),password:this.data.password},'POST',false,false,
    this,getCurrentPages()).then( (res)=>{
      if(res.code == '1'){
        let password = this.data.password;
        console.log(password)
        wx.navigateTo({
          url: '/pages/detail/detail?searchTxt=' + this.data.queryinput,
        })
      }else{
        util.msg(res.msg)
      }
      
      }).catch( (errMsg)=>{});

  },
  //关闭弹窗
  closeMask(){
    this.setData({
      isMask: false,
      isSet: false,
      isQuery: false
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    app.https_request(util.web_url.index,{id:123},'POST',false,false,this,getCurrentPages()).then( (res)=>{
      // console.log(res.data)
      this.setData({noticeText:res.data.notice,tipText:res.data.tstips,src:res.data.tsvideo,poster:res.data.tsvideoPic});
      }).catch( (errMsg)=>{});
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
this.setData({isMask:false,isSet:false,isQuery:false,password:''})
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})